﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    
}
Reload = function(sxType)
{
    var lovhCAR = $id("lovh_CAR.ID");
    var CAR = lovhCAR.value;
    var lovhCompany = $id("lovh_CAR.CUSTOMERID");
    var Company = lovhCompany.value;
    
    var hStart = $id("hStart");
    var hEnd = $id("hEnd");
    var dtmStart = new Date(hStart.value);
    var dtmEnd = new Date(hEnd.value);
    var x = sxType == "NEXT" ? 7 : -7;
    
    dtmStart.setDate(dtmStart.getDate() + x);
    var d1  = dtmStart.getDate();
    var day1 = d1;
    var m1 = dtmStart.getMonth() + 1;
    var month1 = m1;
    var yy1 = dtmStart.getYear();
    var year1 = (yy1 < 1000) ? yy1 + 1900 : yy1;
    
    dtmEnd.setDate(dtmEnd.getDate() + x);
    var d2  = dtmEnd.getDate();
    var day2 = d2;
    var m2 = dtmEnd.getMonth() + 1;
    var month2 = m2;
    var yy2 = dtmEnd.getYear();
    var year2 = (yy2 < 1000) ? yy2 + 1900 : yy2;
    
    hStart.value = month1 + "/" + day1 + "/" + year1;
    hEnd.value = month2 + "/" + day2 + "/" + year2;
    
    var divdate = $id("divDate");
    
    divdate.innerHTML = hStart.value + " - " + hEnd.value;    
    
    dgCA_c.PerformCallback("RELOAD" + DELIMITER + sxType + DELIMITER + Company + DELIMITER + CAR + DELIMITER + hStart.value);
}

Filter = function()
{
    var lovhCAR = $id("lovh_CAR.ID");
    var CAR = lovhCAR.value;
    var lovhCompany = $id("lovh_CAR.CUSTOMERID");
    var Company = lovhCompany.value;
    var load = $id("load");
    var btn = $id("btnFilter");
    btn.style.display = "none";
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
    var hStart = $id("hStart");
    dgCA_c.PerformCallback("FILTER" + DELIMITER + Company + DELIMITER + CAR + DELIMITER + hStart.value);
}
dgCA_c_EndCallback = function(e)
{
    var load = $id("load");
    var btn = $id("btnFilter");
    btn.style.display = "block";
    load.innerHTML = "";
}
ShowPopUp = function (iCarId, sxDay)
{
    var div = $id("popuplayer");
    var hStart = $id("hStart");
    var startDate = hStart.value;
    div.style.display = "block";
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    renderFirst();
    
    cbkCA_c.PerformCallback("SHOW" + DELIMITER + iCarId + DELIMITER + sxDay + DELIMITER + startDate);
}
ClosePopUp = function()
{
    var div = $id("popuplayer");
    div.innerHTML = "";
    div.style.display = "none";
}
cbkCA_c_CallbackComplete = function(e){
    if( e.parameter.startsWith("SHOW") )
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;
    }
    else
    {
        ClosePopUp();
    }
}

SelectCompany = function()
{
    var lovhCompany = $id("lovh_CAR.CUSTOMERID");
    var lovpCAR = $id("lovp_CAR.ID");
    var lovCAR = $id("lov_CAR.ID");
    var lovhCAR = $id("lovh_CAR.ID");
    
    if(lovpCAR.value != lovhCAR.value )
    {    
        lovCAR.value = "";
        lovhCAR.value = "";
    }
    
    lovpCAR.value = lovhCompany.value;
}
SelectCAR = function()
{
    var lovhCAR = $id("lovh_CAR.ID");
    var lovpCompany = $id("lovp_CAR.CUSTOMERID");
    var lovCompany = $id("lov_CAR.CUSTOMERID");
    var lovhCompany = $id("lovh_CAR.CUSTOMERID");
    
    if(lovpCompany.value != lovhCompany.value )
    {    
        lovCompany.value = "";
        lovhCompany.value = "";
    }
    lovpCompany.value = lovhCAR.value;
}
